#pragma once
#include "feature_db.h"
#include <map>
#include <string>

// 

struct vid_data
{
	unsigned long long length;
	unsigned char *data;
};

class database
{
public:
	virtual ~database() {};
	typedef enum { gf = 1, lf, tv } feature_t;
	virtual int get_data(int subclass_id, int b2c_flag, feature_t feat_type, int vid_num, int *vid_list, vid_data *datas) = 0;
};

class database_bdb : public database
{
	struct map_key
	{
		int class_id;
		int subclass_id;
		int b2c_flag;
		feature_t feat_type;
		
		int get_val() const { return class_id * subclass_id * (b2c_flag + 1) * feat_type; }
		bool operator< (const map_key &rhs) { return get_val() < rhs.get_val(); }
		bool operator< (const map_key &rhs) const { return get_val() < rhs.get_val(); }
	};
	
	class map_key_less
	{
	public:
		bool operator() (const map_key &lhs, const map_key &rhs) const { return lhs < rhs; }
	};
	std::map<map_key, feature_db *, map_key_less> _feature_db_map;
	std::string _data_root_path;
public:
	virtual ~database_bdb() {
		for (std::map<map_key, feature_db *>::iterator it = _feature_db_map.begin(); it != _feature_db_map.end(); it++) {
			delete it->second;
		}
	}
	
	void set_data_root_path(const std::string p) { _data_root_path = p; }
	int get_data(int subclass_id, int b2c_flag, feature_t feat_type, int vid_num, int *vid_list, vid_data *datas);
	int get_total_word_count() { return 0x7FFFFFFF / 16; }
private:
	feature_db *find_feature_db(int class_id, int subclass_id, int b2c_flag, feature_t feat_type);
	std::string get_db_path(int class_id, int subclass_id, int b2c_flag, feature_t feat_type);
};

// to be continue
